package com.gid.rcflightlogger;


import java.util.Date;

import android.content.Context;

import com.orm.androrm.BooleanField;
import com.orm.androrm.CharField;
import com.orm.androrm.DateField;
import com.orm.androrm.Model;
import com.orm.androrm.OneToManyField;
import com.orm.androrm.QuerySet;

public class Aircraft extends Model {
	
	public static final QuerySet<Aircraft> objects(Context context) {
		return objects(context, Aircraft.class);
	}
	
	public static final String[] TYPE_ARRAY = {"Chopper", "Plane", "Other"};
	public static final String ID_LABEL = "AircraftID"; //used for passing/saving states
	public static final int NAME_LEN = 18;
	public static final String DEFAULT_TYPE = "Helicopter";
	
	protected CharField mType;
	protected CharField mName;
	protected DateField mBuildDate; //YYYY-MM-DDTHH:MM:SS
	protected DateField mRegisterDate;
	protected BooleanField mStatus;
	protected CharField mNotes;
	protected OneToManyField<Aircraft, Flight> mFlights;
	
	//constructor
	public Aircraft() {
		super();
		
		mType = new CharField();
		mName = new CharField(NAME_LEN);		
		mBuildDate = new DateField();
		mRegisterDate = new DateField();
		mStatus = new BooleanField();
		mNotes = new CharField();
		mFlights = new OneToManyField<Aircraft, Flight>(Aircraft.class, Flight.class);
		reset();
	}
	
	//reset all fields to default value
	public void reset()
	{
		mType.set(DEFAULT_TYPE);
		mName.set("");
		Date current_date = new Date();
		mBuildDate.set(current_date);
		mRegisterDate.set(current_date);
		mStatus.set(true);
		mNotes.set("");
	}

	//member access methods
	public String getType() {
		return mType.get();
	}
	
	public void setType(String type) {
		mType.set(type);
	}
	
	public String getName() {
		return mName.get();
	}
	
	public void setName(String name) {
		
		mName.set(name);
	}
	
	public Date getBuildDate() {
		return mBuildDate.get();
	}
	
	public void setBuildDate(Date d) {
		mBuildDate.set(d);
	}
	
	public Date getRegisterDate() {
		return mRegisterDate.get();
	}
	
	public void setRegisterDate(Date d) {
		mRegisterDate.set(d);
	}
	
	public boolean getStatus() {
		return mStatus.get();
	}
	
	public void setStatus(boolean status) {
		mStatus.set(status);
	}
	
	public String getNotes() {
		return mNotes.get();
	}
	
	public void setNotes(String notes) {
		
		mNotes.set(notes);
	}
	
	public QuerySet<Flight> getFlights(Context context) {
		return mFlights.get(context, this);
	}
	
	//implement toString method for use by Spinner adaptor
	public String toString()
	{
		return mName.get();
	}
}
